﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Utils.Common;
using ZK.BLL;
using ZK.Entity;

namespace ZK.Client.WinForm
{
    public partial class FrmProductEdit : Form
    {
        public FrmProductEdit()
        {
            InitializeComponent();
        }

        public ProductInfo ProductInfo { get; set; }

        private void FrmProductEdit_Load(object sender, EventArgs e)
        {

            if (Class_Config.PrinetType == "WDJ" || Class_Config.PrinetType == "VDJ")
            {
                cmbTempalte.DataSource =   VDJTemplateBLL.Instance.GetList().Select(s=>s.TemplateName).ToArray();
            }
            else {
                cmbTempalte.DataSource = CIJTemplateBLL.Instance.GetList().Select(s => s.TemplateName).ToArray();
            }

            string[] files = Directory.GetFiles(ConfigBase.LogoImg);

            foreach (var file in files)
            {
                cmbCustomer.Items.Add(Path.GetFileNameWithoutExtension(file));
            }

            foreach (var file in files)
            {
                cmbCustomer2.Items.Add(Path.GetFileNameWithoutExtension(file));
            }


            if (ProductInfo != null)
            {
                cmbCustomer.SelectedIndex = cmbCustomer.FindString(ProductInfo.CustomerName);
                txtProductName.Text = ProductInfo.ProductName;
                txtOther.Text = ProductInfo.Other;

                cmbTempalte.SelectedIndex = cmbTempalte.FindString(ProductInfo.TemplateName);

                if (!string.IsNullOrEmpty(ProductInfo.CustomerName2))
                { 
                    cmbCustomer2.SelectedIndex = cmbCustomer2.FindString(ProductInfo.CustomerName2);
                }
                //txtTemplate.Text = ProductInfo.TemplateName;
            }
            else {
                ProductInfo = new ProductInfo();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSure_Click(object sender, EventArgs e)
        {

            ProductInfo.CustomerName = cmbCustomer.Text;
            ProductInfo.ProductName = txtProductName.Text;
            ProductInfo.Other = txtOther.Text;
            ProductInfo.TemplateName = cmbTempalte.Text.Trim();
            ProductInfo.CustomerName2 = cmbCustomer2.Text.Trim();
            this.DialogResult = DialogResult.OK;

            this.Close();
        }

     
    }
}
